package com.lry.jvm.instructions.stack;

import com.lry.jvm.instructions.base.NoOperandsInstruction;
import com.lry.jvm.rtda.Frame;
import com.lry.jvm.rtda.OperandStack;
import com.lry.jvm.rtda.Slot;
//复制栈顶部两个字长的内容，然后将复制内容及原来弹出的三个字长的内容压入栈
public class dup2_x1 extends NoOperandsInstruction {
    @Override
    public byte getOpCode() {
        return 0x5d;
    }

    @Override
    public void execute(Frame frame) throws Exception {
        OperandStack operandStack = frame.getOperandStack();
        Slot slot1 = operandStack.popSlot();
        Slot slot2 = operandStack.popSlot();
        Slot slot3 = operandStack.popSlot();


        operandStack.pushSlot(slot2);
        operandStack.pushSlot(slot1);

        operandStack.pushSlot(slot3);
        operandStack.pushSlot(slot2);
        operandStack.pushSlot(slot1);
    }
}
